package com.chaopei.character;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Corday 天涯
 * @Date 2022/3/7 11:34
 */
//final/abstract
public class MyChar {//外部类
    private String name;
//    全局的静态变量,所有对象都共享
    static  int level = 30;
//    全局静态常量,所有对象共享,不可更改
    final  static  double PI=Math.PI;
//  全局常量对象
    final  static List list=new ArrayList();
    public MyChar(String name) {
        this.name = name;
    }

    //static
    class Inner {//内部类
        public String getInfo() {
            return "名称:"+MyChar.this.name;
        }
    }

    //  静态内部类
    static class MyInner {
       public String getInfo(){
           return "等级:"+MyChar.level;
       }
    }
}
class  MyMainc{
    public static void main(String[] args) {
//        1.创建非静态内部对象
        MyChar myChar = new MyChar("外部类");
        MyChar.Inner inner = myChar.new Inner();
        System.out.println(inner.getInfo());
//       2.创建静态内部类
        System.out.println("------------------");
        MyChar.MyInner myInner = new MyChar.MyInner();
        System.out.println(myInner.getInfo());
//        修改level,并创建一个新的对象再调用输出
        MyChar.level = 40;
        //直接通过类名创建
        MyChar.MyInner myInner1 = new MyChar.MyInner();
        System.out.println(myInner.getInfo());
        System.out.println(myInner1.getInfo());
    }
}